#!/usr/bin/env node

const api = require('./index')
const { program } = require('commander');
const pkg=require('./package.json')

program
  .verson(pkg.version)
    .option('-x, --xxx', 'what x')
program
  .command('add')
  .description('add a task')
  .action((...args) => {
    const words=args.slice(1).join(' ')
    api.add(words).then(()=>{console.log("add success")},()=>{console.log("add failed")})
  });
program
  .command('clear')
  .description('clear all tasks')
  .action(() => {
    api.clear().then(()=>{console.log("clear success")},()=>{console.log("clear failed")})
  });
program
  .command('showAll')
  .description('show all tasks')
  .action(() => {
    void api.showAll()
  });
program.parse(process.argv);

if(process.argv.length===2){
  void api.showAll()
}
